package com.daidai.service.room.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.daidai.dao.RoomMapper;
import com.daidai.domain.Room;
import com.daidai.service.room.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    RoomMapper roomMapper;

    public List<Room> getAllRoom(){
        return roomMapper.getAllRoom();
    }

    public List<Room> getAllFullRoom() {
        return roomMapper.getAllFullRoom();
    }

    public List<Room> getAllRemainRoom() {

        return roomMapper.getAllRemainRoom();
    }

    public List<Room> getAllStopRoom() {
        return roomMapper.getAllStopRoom();
    }

    //todo
    @Override
    public Integer addRoom(Room room) {
        return 1;
    }


    @Override
    public Integer updateRoom(Room room) {
        QueryWrapper<Room> wrapper = new QueryWrapper<>();
        wrapper.eq("rid",room.getRid());
        boolean exists = roomMapper.exists(wrapper);
        if(exists){
            return  roomMapper.update(room,wrapper);
        }else
        {
            return 0;
        }
    }

    @Override
    public Integer delRoom(Integer rid) {
        return roomMapper.delete(new QueryWrapper<Room>().eq("rid",rid));
    }

    @Override
    public List<Room> getAllRoomByType(int typeid) {
        return roomMapper.getAllRoomByType(typeid);
    }

    @Override
    public List<Room> getAllRoomByAsc() {
        return roomMapper.getAllRoomByAsc();
    }

    @Override
    public List<Room> getAllRoomByDesc() {
        return  roomMapper.getAllRoomByDesc();
    }

    @Override
    public Room getRoomByRid(int rid) {
        return roomMapper.getRoomById(rid);
    }
}
